package com.owc.controller.app;

import com.owc.common.custom.annotation.Advice;
import com.owc.domain.BaseResult;
import com.owc.domain.PageVo;
import com.owc.domain.dto.OrderDTO;
import com.owc.domain.dto.OrderDetailDTO;
import com.owc.domain.entity.Order;
import com.owc.domain.vo.SingleIdVo;
import com.owc.service.app.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author xiaom
 * @Date 2020/2/25 17:48
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping("/order")
@Api(tags = "(APP-V2)订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping(value = "/getOrderList")
    @ApiOperation("获取订单记录")
    public BaseResult<OrderDTO> getOrderList(@RequestBody PageVo pageVo){
        return BaseResult.makePageBean(orderService.getOrderList(pageVo.getPageIndex(),pageVo.getPageSize()));
    }

    @PostMapping(value = "/getOrderDetail")
    @ApiOperation("获取订单详情")
    public BaseResult<OrderDetailDTO> getOrderDetail(@RequestBody @Valid SingleIdVo singleIdVo){
        return BaseResult.success(orderService.getOrderDetail(singleIdVo.getId()));
    }

    @PostMapping(value = "/redemption")
    @ApiOperation("赎回")
    public BaseResult<Boolean> redemption(@RequestBody @Valid SingleIdVo singleIdVo) throws Exception {
        return BaseResult.success(orderService.redemption(singleIdVo.getId()));
    }
}
